/*
 * Copyright 2018 the original author or authors.
 *
 * you can use the file or import project.but Do not take legal responsibility.
 * Only for learning communication.
 *
 * Java compiled version 1.8 or higher
 *
 *
 *
 *
 */
package org.liang.downimage.util;

import java.util.ArrayList;
import java.util.List;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

/**
 * url工具类
 * @author houliang
 * @date 2018年1月27日
 */
public abstract class UrlUtil {

	/**
	 * 从html页面获取所有url链接 
	 * @param url
	 * @return
	 */
	public static List<String> getUrl(String url) {
		List<String> paths = new ArrayList<String>();
		if(url == null) {
			return paths;
		}
		try {
			Document doc = Jsoup.connect(url).get();
			Elements links = doc.select("a[href]");

			for (Element link : links) {
				String href = link.attr("abs:href");
				paths.add(href);
			}
		} catch (Exception e) {
			System.err.println("获取链接异常");
		}
		return paths;
	}
}
